package com.zhuss.job.processor;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.job.job.CreateJobTopicBo;
import com.zhuss.bean.bo.job.job.wechat.TopicJobBo;
import com.zhuss.bean.vo.job.job.DetailJobVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;

/**
 * 评论职位 processor
 * @Author: zhushanshuo
 * @Date: 2020/02/28 16:01
 */
@Component("jobTopic")
public class JobTopic extends AbstractProcessor<Object, TopicJobBo> implements Processor<Object, TopicJobBo> {

    @Autowired
	@Qualifier("jobRead")
	private JobRead jobRead;
    
    @Autowired
	@Qualifier("jobTopicCreate")
	private Processor<Object, CreateJobTopicBo> jobTopicCreate;
    
    /**
     * 校验
     */
    @Override
    public void check(TopicJobBo bo) throws WpsException {
    	
    }
    
    /**
     * 操作方法
     * @throws WpsException 
     */
    @Override
    public Object process(TopicJobBo param) throws WpsException {
    	
    	Long jobId = param.getJobId();
    	DetailJobVo job = ((DetailJobVo) jobRead.detail(jobId));
    	String name = job.getTitle();
    	
    	CreateJobTopicBo bo = new CreateJobTopicBo();
    	BeanUtils.copyProperties(param, bo);
    	BeanUtils.copyProperties(job, bo);
    	bo.setJobId(jobId);
    	bo.setTopicContent(param.getContent());
    	bo.setTitle(job.getTitle());
    	bo.setCompany(job.getCompany());
    	bo.setStation(job.getStation());
    	bo.setTreatment(job.getTreatment());
    	bo.setAddress(job.getAddress());
    	bo.setPhone(job.getPhone());
    	bo.setPic(job.getPic());
    	bo.setWx(job.getWx());
    	bo.setBlog(job.getBlog());
    	bo.setQq(job.getQq());
    	bo.setIntroduction(job.getIntroduction());
    	jobTopicCreate.process(bo);
    	
    	
    	
    	param.setName(name);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(TopicJobBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.职位.key());
    	record.setAction(LogActionEnum.职位评论.key());
    	record.setTargetId(param.getJobId());
    	record.setTargetName(param.getName());
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
